package pers.brozen.anka.utils;

import org.apache.http.client.HttpClient;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;

/**
 * @author Brozen
 * @date 2019/11/19 11:25 AM
 */
public class HttpClientHolder {
    // 读取超时
    private final static int SOCKET_TIMEOUT = 10000;

    // 连接超时
    private final static int CONNECTION_TIMEOUT = 10000;

    // 每个HOST的最大连接数量
    private final static int MAX_CONN_PRE_HOST = 20;

    // 连接池的最大连接数
    private final static int MAX_CONN = 60;

    private static HttpClient client;

    private static PoolingHttpClientConnectionManager manager;


    static {
        manager = new PoolingHttpClientConnectionManager();
        manager.setMaxTotal(MAX_CONN);
        manager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(SOCKET_TIMEOUT).build());
        client = HttpClients.custom().setConnectionManager(manager).build();
    }

    public static HttpClient getClient() {
        return client;
    }





}
